/*
 * The Open Source Unix Installer
 *
 * The MIT License
 *
 * Copyright 2011-2012 Andrey Pudov.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

/*
 * @author  Andrey Pudov    <andrey@andreypudov.com>
 * @version 0.00.00
 * @name    u_crc32.h
 * @date:   Jun 16, 2012
 */

#ifndef INSTALLER_UTIL_XML_U_CRC32_H_
#define INSTALLER_UTIL_XML_U_CRC32_H_

#include "crc32.h"

#include "u_main.h"

#ifdef __cplusplus
extern "C" {
#endif

bool u_installer_crypt_crc32_start();             /* unit entry point */

bool u_installer_crypt_crc32();

bool u_installer_crypt_crc32_start() {
    return (u_installer_crypt_crc32());
}

bool u_installer_crypt_crc32() {
    char *string1 = "0123456789";
    char *string2 = "ABCDEFGHIJ";
    char *string3 = "AbCdEfGhIj";
    char *string4 = "!@#$%^&*()";
    
    u_int32_t hash1 = 0xA684C7C6;
    u_int32_t hash2 = 0x321E6D05;
    u_int32_t hash3 = 0xBDB09F16;
    u_int32_t hash4 = 0xAEA29B98;
    
    u_int32_t result1 = installer_crypt_crc32((u_int8_t*) string1, 10);
    u_int32_t result2 = installer_crypt_crc32((u_int8_t*) string2, 10);
    u_int32_t result3 = installer_crypt_crc32((u_int8_t*) string3, 10);
    u_int32_t result4 = installer_crypt_crc32((u_int8_t*) string4, 10);

    if ((result1 != hash1)
            || (result2 != hash2)
            || (result3 != hash3)
            || (result4 != hash4)) {
        u_installer_main_print("crc32", "crc32()", false);
        u_installer_main_trace("crc32", "crc32()", 
            "\tstring1: %s, \texpected: 0x%x, \tvalue: 0x%x\n" \
            "\tstring2: %s, \texpected: 0x%x, \tvalue: 0x%x\n" \
            "\tstring3: %s, \texpected: 0x%x, \tvalue: 0x%x\n" \
            "\tstring4: %s, \texpected: 0x%x, \tvalue: 0x%x\n",
                string1, hash1, result1,
                string2, hash2, result2,
                string3, hash3, result3,
                string4, hash4, result4);
                                   
        return false;
    }
    
    u_installer_main_print("crc32", "crc32()", true);
    return true;
}


#ifdef __cplusplus
}
#endif

#endif /* INSTALLER_UTIL_XML_U_CRC32_H_ */ 
